package org.testis.webautomationmodule.data;

import java.io.Serializable;


/**
 * A class to define any data node  of a web automation test step
 * @author nurhat
 */
public class WebAutomationModuleDataNode implements Serializable
{

    private static final long serialVersionUID = 19828L;
    private String m_objectType;
    private String m_abstractId;
    private Object[] m_parameters;


    /**
     * Only constructor to create a web automationnode.
     * @param m_objectType defines type of object to create. e.g. UIButton,UITextBox
     * @param m_parameters defines m_parameters to be able to create the ui object
     */
    public WebAutomationModuleDataNode(String objectType,
                                       Object[] parameters)
    {
        setObjectType(objectType);
        setParameters(parameters);
        setAbstractId("");
    }


    /**
     * Only constructor to create a web automationnode.
     * @param m_objectType defines type of object to create. e.g. UIButton,UITextBox
     * @param m_parameters defines m_parameters to be able to create the ui object
     * @param abstractId defines abstractId of the ui object
     */
    public WebAutomationModuleDataNode(String objectType,
                                       Object[] parameters,
                                       String abstractId)
    {
        setObjectType(objectType);
        setParameters(parameters);
        setAbstractId(abstractId);
    }


    public Object[] getParameters()
    {
        return m_parameters;
    }


    public String getObjectType()
    {
        return m_objectType;
    }


    public void setObjectType(String objectType)
    {
        this.m_objectType = objectType;
    }


    public void setParameters(Object[] parameters)
    {
        this.m_parameters = parameters;
    }


    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        if (getObjectType() != null) {
            sb.append(" type: " + getObjectType());
        }

        if (m_parameters != null) {

            sb.append(" params { ");
            for (int i = 0; i < m_parameters.length; i++) {

                if (i == 0 && m_parameters[i] != null) {
                    sb.append(" param " + i + ":" + m_parameters[i].toString());
                }
                else if (m_parameters[i] != null) {
                    sb.append(" , param " + i + ":" + m_parameters[i].toString());
                }
            }
            sb.append("}");
        }

        return sb.toString();
    }


    public String getAbstractId()
    {
        return m_abstractId;
    }


    public void setAbstractId(String m_abstractId)
    {
        this.m_abstractId = m_abstractId;
    }
}
